<template>
    <div>
        <h1>登录页面</h1>
        <table class="table">
            <thead>
                <tr>
                    <td>用户名</td>
                    <td>
                        <input type="text" v-model="data.username">
                    </td>
                </tr>
                <tr>
                    <td>用户名</td>
                    <td>
                        <input type="password" v-model="data.password">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="登录" @click="Deng">
                    </td>
                </tr>
            </thead>
        </table>
    </div>
    <br>
    <a href="/Hlist">会员显示列表</a> 
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
//实例化
const router=useRouter();
//登录Model
const data=ref({
    username:"",
    password:""
})
const Deng=()=>{
    if(data.value.username=="")
    {
        alert("用户名不能为空");
        return;
    }
    if(data.value.password=="")
    {
        alert("用户密码不能为空");
        return;
    }
    axios.get("https://localhost:7258/api/Hui/Login",{params:data.value}).then(res=>{
        if(res.data.HId==-1)
        {
            alert("用户名不存在，登录失败");
        }
        if(res.data.HId==-2)
        {
            alert("密码错误，登录失败");
        }
        if(res.data.HId>0)
        {
            alert("登陆成功");
            router.push({path:"/hlist"})
        }
    })
}










</script>

<style scoped>

</style>